package com.lingnan.work01.controller;

import com.lingnan.work01.entity.Student;
import com.lingnan.work01.service.StudentService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 学生信息表(Student)表控制层
 *
 * @author makejava
 * @since 2020-05-27 22:14:12
 */
@RestController
@RequestMapping("student")
public class StudentController {
    /**
     * 服务对象
     */
    @Resource
    private StudentService studentService;


    @RequestMapping("importexcel")
    public String adminImportStudent(HttpServletResponse response, HttpServletRequest request) throws Exception {
        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
        List<List<Object>> listob = null;
        MultipartFile file = multipartRequest.getFile("file");
        System.out.println((studentService == null) + "--------");
        studentService.impExcel(file);
        System.out.println("............");
        return "redirect:/emps";
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Student selectOne(Integer id) {
        return this.studentService.queryById(id);
    }

}